<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   plain
                   v-if="permission.cityworkOverdue_delete"
                   @click="handleDelete">删 除
        </el-button>
      
      </template>
       <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-phone-outline"
          size="small"
          @click.stop="handleDetail(scope.row,scope.index)"
          v-if="scope.row.dealStatus=='1'"
        >查看详情
        </el-button>
        <el-button
          type="text"
          icon="el-icon-finished"
          size="small"
          @click.stop="handleOldOrder(scope.row,scope.index)"
          v-if="scope.row.receiveTimes>0 "
        >历史单
        </el-button>
       </template>
      <template slot-scope="{row}"
                slot="urgencyDegree">
        <el-tag>{{row.urgencyDegree}}</el-tag>
      </template>
    </avue-crud>
   <!-- 查看工单详情 -->
    <el-dialog title="工单信息"
                   append-to-body
                   :visible.sync="viewReplayBoxShow"
                   width="50%">
    <el-form ref="ViewReplayForm" :rules="rules" :model="viewReplayForm" label-width="180px" size="mini">
     <el-card shadow="hover">
        <el-row>
          <el-col :span="24">
            <el-form-item label="工单号：" >
            {{ viewReplayForm.workId  }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="接收时间：">
                {{ viewReplayForm.receiptTime }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="问题描述：">
               {{ viewReplayForm.problemDescription }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="工单附件：">
              空
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="转办意见：">
               {{ viewReplayForm.administrativeOpinions }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="回复时限：">
                {{ viewReplayForm.timeLimit }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="联系人：">
               {{ viewReplayForm.contact }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="联系电话：">
               {{ viewReplayForm.contactPhone }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="地址：">
               {{ viewReplayForm.address }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="紧急程度：">
               {{ viewReplayForm.urgencyDegree }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="是否保密：">
                {{ viewReplayForm.confidentiality }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="是否回复：">
              {{ viewReplayForm.replyFlag }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="回复备注：">
              {{ viewReplayForm.replyRemark }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="办理轨迹：">
               {{ viewReplayForm.handlerTrack }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="转办人：">
              {{ viewReplayForm.administrativePerson }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="受理类型：">
              {{ viewReplayForm.accessType }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="受理员：">
              {{ viewReplayForm.acceptorName }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="受理员工号：">
              {{ viewReplayForm.acceptorNumber }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="录入时间：">
              {{ viewReplayForm.inputTime }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="信息来源：">
              {{ viewReplayForm.messageSource }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="分类：">
              {{ viewReplayForm.classify }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="工单类型：">
              {{ viewReplayForm.workOrderType }}
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="操作记录：" style="white-space: pre-wrap">
              {{ historyDetail }}
            </el-form-item>
          </el-col>
        </el-row>
         <el-row>
              <el-form-item class="align-text:center">
                <el-button @click="handleViewReplayCancel()">关闭</el-button>
              </el-form-item>
         </el-row>
      </el-card>
     </el-form>
    </el-dialog>
    <el-dialog title="历史工单"
                   append-to-body
                   :visible.sync="oldOrderBoxShow"
                   width="80%">
        <el-table
                  :data="oldOrderData"
                  border
                  style="width: 100%">
                  <el-table-column
                    fixed
                    type="index"
                    label="序号"
                    width="50">
                  </el-table-column>
                  <el-table-column
                    prop="workId"
                    label="工单号"
                    width="160">
                  </el-table-column>
                  <el-table-column
                    prop="receiptTime"
                    label="接收时间"
                    width="180">
                  </el-table-column>
                  <el-table-column
                    prop="problemDescription"
                    label="问题描述"
                    show-overflow-tooltip = "true"
                    width="150">
                  </el-table-column>
                  <el-table-column
                    prop="administrativeOpinions"
                    label="转办意见"
                    show-overflow-tooltip = "true"
                    width="150">
                  </el-table-column>
                  <el-table-column
                    prop="timeLimit"
                    label="转办时限"
                    width="180">
                  </el-table-column>
                  <el-table-column
                    prop="contact"
                    label="联系人"
                    width="120">
                  </el-table-column>
                  <el-table-column
                    prop="contactPhone"
                    label="联系电话"
                    width="120">
                  </el-table-column>
                  <el-table-column
                    prop="urgencyDegree"
                    label="紧急程度"
                    width="120">
                  </el-table-column>
                  <el-table-column
                    prop="replyFlag"
                    label="是否回复"
                    width="120">
                  </el-table-column>
                  <el-table-column
                    prop="classify"
                    label="分类"
                    show-overflow-tooltip = "true"
                    width="200">
                  </el-table-column>
                  <el-table-column
                    prop="workOrderType"
                    label="工单类型"
                    width="120">
                  </el-table-column>
                   <el-table-column
                    prop="administrativePerson"
                    label="转办人"
                    width="160">
                  </el-table-column>
                   <el-table-column
                    prop="accessType"
                    label="受理类型"
                    width="120">
                  </el-table-column>
                   <el-table-column
                    prop="inputTime"
                    label="录入时间"
                    width="180">
                  </el-table-column>
      </el-table>
    </el-dialog>
  </basic-container>
</template>

<script>
  import {getList, remove} from "@/api/govsvc/cityworkOverdue";
  import {
          getRejectDetail,
          getOldOrderList
          } from "@/api/govsvc/citywork";
  import {mapGetters} from "vuex";
  export default {
    data() {
      return {
        form: {},
         //查看回复信息form
        viewReplayForm: {

        },
        historyDetail: [],
         //历史单列表数据
        oldOrderData: [],
        viewReplayBoxShow: false,//查看回复信息窗口显示
        oldOrderBoxShow: false,//历史单窗口显示
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          indexLabel:'序号',
          height: 'auto',
          calcHeight: 30,
          dialogWidth: 850,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: false,
          addBtn: false,
          editBtn: false,
          delBtn: false,
          selection: true,
          excelBtn: false,
          dialogClickModal: false,
          column: [
            {
              label: "工单号",
              prop: "workId",
              type: "input",
              search: true,
              minWidth: 120,
            },
            {
              label: "接收时间",
              prop: "receiptTime",
              type: "date",
              readonly: true,
              disabled:true,
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
            },
            {
              label: "问题描述",
              prop: "problemDescription",
              type: "input",
                overHidden: true,
            },
            {
              label: "转办意见",
              prop: "administrativeOpinions",
              type: "input",
              hide: true,
            },
            {
              label: "转办时限",
              prop: "timeLimit",
              type: "date",
              readonly: true,
              disabled:true,
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
             
            },
            {
              label: "联系人",
              prop: "contact",
              type: "input",
            },
            {
              label: "联系电话",
              prop: "contactPhone",
              type: "input",
            },
          
            {
              label: "紧急程度",
              prop: "urgencyDegree",
              type: "input",
              slot: true,
            },
         
            {
              label: "是否回复",
              prop: "replyFlag",
              type: "input",
            },
            {
              label: "分类",
              prop: "classify",
              type: "select",
              hide: true,
            },
            {
              label: "工单类型",
              prop: "workOrderType",
              type: "input",
            },
            {
              label: "工单录入次数",
              prop: "receiveTimes",
              type: "input",
              hide: true,
            },
            {
              label: "是否存在附件",
              prop: "hasFile",
              type: "input",
              hide: true,
            },
            {
              label: "分配单位",
              prop: "deptId",
              type: "select",
              search: true,
              readonly: true,
              disabled:true,
              dicUrl: "/api/smart-system/dept/getDeptList",
              span: 8,
              props: {
                label: "title",
                value: "key"
              },
            },
            {
              label: "工单状态",
              prop: "dealStatus",
              type: "select",
              dicData: [
                {
                  label: "未分配",
                  value: "0"
                },
                {
                  label: "已分配",
                  value: "1"
                },
                {
                  label: "已处理",
                  value: "2"
                }
              ],
            },
            {
              type: "daterange",
              label: "接收时间",
              span: 8,
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
              prop: "receiptTimeRange",
              searchRange: true,
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              search: true,
            },
          ]
        },
        data: [],
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.cityworkOverdue_add, false),
          viewBtn: this.vaildData(this.permission.cityworkOverdue_view, false),
          delBtn: this.vaildData(this.permission.cityworkOverdue_delete, false),
          editBtn: this.vaildData(this.permission.cityworkOverdue_edit, false)
        };
      },
      workIds() {
        let workIds = [];
        this.selectionList.forEach(ele => {
          workIds.push(ele.workId);
        });
        return workIds.join(",");
      }
    },
    methods: {
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(row.workId);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(this.workIds);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
       //查看回复详情
      handleDetail(row){
          getRejectDetail(row.workId).then(res => {
          console.log(res.data.data);
            this.viewReplayForm = res.data.data.citywork;
            this.historyDetail = res.data.data.historyDetail;
            this.viewReplayBoxShow = true;
            
          });
      },
      //历史单列表显示
      handleOldOrder(row){
          console.log(row.workId);
          this.oldOrderBoxShow = true;
          getOldOrderList(row.workId).then(res => {
            const data = res.data.data;
            this.oldOrderData = data;
          });


      },
       //查看弹出层关闭
      handleViewReplayCancel(){
          this.viewReplayBoxShow = false;
      },
      beforeOpen(done) {
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
          const {receiptTimeRange} = params;
        let values = {
          ...params,
        };
        if (receiptTimeRange) {
          values = {
            ...params,
             receiptTimeDatege: receiptTimeRange[0],
             receiptTimeDatelt: receiptTimeRange[1],
          };
          values.receiptTimeRange = null;
          this.query.receiptTimeRange = null;
        }
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(values, this.query)).then(res => {
          console.log(res.data.data);
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>
<style>
  .box {
    height: 800px;
  }

  .el-scrollbar {
    height: 100%;
  }

  .box .el-scrollbar__wrap {
    overflow: scroll;
  }
</style>